/**
 * 
 */
package com.project.cris.MBean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.project.entity.*;
import com.project.cris.SessionBean.*;
/**
 * @author Solomon
 *
 */
@ManagedBean(name="mProperty_Search")
@SessionScoped
public class MProperty_Search {

	/**
	 * @throws Exception 
	 * 
	 */
	public MProperty_Search() throws Exception {
		if(selectedProType.equals("p4r")){
			
		}
		
		// TODO Auto-generated constructor stub
	}
	
	private Property prop;
	private PropForRent propRent;
	private PropForSale propSale;
	private RoomForRent roomRent;

	
	
	private ArrayList<Property> allProperty;
	private ArrayList<PropForRent> allPropForRent;
	private ArrayList<PropForSale> allPropForSale;
	private ArrayList<RoomForRent> allRoomForRent;
	private ArrayList<PropForRent> searchPropForRent;
	private ArrayList<PropForSale> searchPropForSale;
	private ArrayList<RoomForRent> searchRoomForRent;
	private ArrayList<Property_Image> findImages;

	private List<String> list;
    private MPaginator paginator;

	
	private double fromPrice;
	private double toPrice;
	
	private String title;
	private String address;
	private String state;
	private int bedRoomMin;
	private int bedRoomMax;
	private int bathRoomMin;
	private int bathRoomMax;
	private double rentpriceFrom;
	private double rentpriceTo;
	private String typesale;
	private double squareMin;
	private double squareMax;
	private String status;
	private String hasinterior;
	private int bedroom;
	private int bathroom;
	private double price;
	private double square;
	private double rent;
	
	private boolean nullCheck=true;
	private boolean checkSize=false;
	private boolean checkSize1=false;
	private boolean checkSize2=false;
	private String selectedProType="p4r";
	

	private String currentPropID;
	private String addr;
	public void setProp(Property prop) {
		this.prop = prop;
	}



	public Property getProp() {
		return prop;
	}
	public void setPropRent(PropForRent propRent) {
		this.propRent = propRent;
	}
	public PropForRent getPropRent() {
		return propRent;
	}
	public void setPropSale(PropForSale propSale) {
		this.propSale = propSale;
	}
	public PropForSale getPropSale() {
		return propSale;
	}
	public void setRoomRent(RoomForRent roomRent) {
		this.roomRent = roomRent;
	}
	public RoomForRent getRoomRent() {
		return roomRent;
	}
	
	
	
	
	
	public void setAllProperty(ArrayList<Property> allProperty) {
		this.allProperty = allProperty;
	}
	public ArrayList<Property> getAllProperty() {
		return allProperty;
	}
	public void setAllPropForRent(ArrayList<PropForRent> allPropForRent) {
		this.allPropForRent = allPropForRent;
	}
	public ArrayList<PropForRent> getAllPropForRent() throws Exception {
		Context ctx = new InitialContext();
		Search_PropForRentRemote proRe = (Search_PropForRentRemote) ctx
				.lookup("MySweetHome/Search_PropForRentBean/remote");
		allPropForRent = proRe.getAllPropForRent();
		if (allPropForRent.size() != 0) {
			this.nullCheck = false;
			return allPropForRent;
		} else
			return null;
	}
	public ArrayList<Double> list(){
		ArrayList<Double> price=new ArrayList<Double>();
		for(int i=0;i<allPropForRent.size();i++){
			price.add(i, allPropForRent.get(i).getDeposit());
		}
		return price;
	}
	public void setAllPropForSale(ArrayList<PropForSale> allPropForSale) {
		this.allPropForSale = allPropForSale;
	}
	public ArrayList<PropForSale> getAllPropForSale() throws Exception {
		Context ctx = new InitialContext();
		Search_PropForSaleRemote proRe = (Search_PropForSaleRemote) ctx
				.lookup("MySweetHome/Search_PropForSaleBean/remote");
		allPropForSale = proRe.getAllPropForSale();
		if (allPropForSale.size() != 0) {
			this.nullCheck = false;
			return allPropForSale;
		} else
			return null;
	}
	public void setAllRoomForRent(ArrayList<RoomForRent> allRoomForRent) {
		this.allRoomForRent = allRoomForRent;
	}
	public ArrayList<RoomForRent> getAllRoomForRent() throws Exception {
		Context ctx = new InitialContext();
		Search_RoomForRentRemote proRe = (Search_RoomForRentRemote) ctx
				.lookup("MySweetHome/Search_RoomForRentBean/remote");
		allRoomForRent = proRe.getAllRoomForRent();
		if (allRoomForRent.size() != 0) {
			this.nullCheck = false;
			return allRoomForRent;
		} else
			return null;
	}
	
	public String getPath(String propID) throws Exception {
		Context ctx = new InitialContext();
		Search_PropertyBeanRemote propRe = (Search_PropertyBeanRemote) ctx
				.lookup("MySweetHome/Search_PropertyBean/remote");
		String path = propRe.getRandomIMGPath(propID);
		return path;
	}
	public ArrayList<Property_Image>searchImages(String propID) throws Exception{
		Context ctx = new InitialContext();
		Search_PropertyBeanRemote propRe = (Search_PropertyBeanRemote) ctx
				.lookup("MySweetHome/Search_PropertyBean/remote");
		findImages = propRe.findImageByPropID(propID);
		return findImages;
	}
	
	 
	
	
	public ArrayList<PropForRent> searchPropForRentAdvanceMethod() throws Exception{
		Context ctx = new InitialContext();
		Search_PropForRentRemote proRe=(Search_PropForRentRemote) ctx.lookup("MySweetHome/Search_PropForRentBean/remote");
		processField();
		setSearchPropForRent(proRe.advanceSearch(fromPrice, toPrice, rentpriceFrom, rentpriceTo, bedRoomMin, bedRoomMax, bathRoomMin, bathRoomMax));
		if(getSearchPropForRent().size()==0){
			this.setCheckSize(false);
		}else{this.setCheckSize(true);}
		this.nullCheck=false;
		paginator=new MPaginator(searchPropForRent);
		return getSearchPropForRent();
		
	}
	public ArrayList<PropForRent> searchPropForRentSimpleMethod() throws Exception{
		Context ctx = new InitialContext();
		Search_PropForRentRemote proRe=(Search_PropForRentRemote) ctx.lookup("MySweetHome/Search_PropForRentBean/remote");
		setSearchPropForRent(proRe.simpleSearch(title, address));
		if(getSearchPropForRent().size()==0){
			this.setCheckSize(false);
		}else{this.setCheckSize(true);}
		this.nullCheck=false;
		paginator=new MPaginator(searchPropForRent);
		return getSearchPropForRent();
	}
	public ArrayList<PropForSale> searchPropForSaleSimpleMethod() throws Exception{
		Context ctx = new InitialContext();
		Search_PropForSaleRemote proRe=(Search_PropForSaleRemote) ctx.lookup("MySweetHome/Search_PropForSaleBean/remote");
		setSearchPropForSale(proRe.simpleSearch(title, address,typesale));
		if(getSearchPropForSale().size()==0){
			this.setCheckSize1(false);
		}else{this.setCheckSize1(true);}
		this.nullCheck=false;
		paginator=new MPaginator(searchPropForSale);
		return getSearchPropForSale();
	}
	public ArrayList<PropForSale> searchPropForSaleAdvanceMethod() throws Exception{
		Context ctx = new InitialContext();
		Search_PropForSaleRemote proRe=(Search_PropForSaleRemote) ctx.lookup("MySweetHome/Search_PropForSaleBean/remote");
		processField();
		setSearchPropForSale(proRe.advanceSearch(fromPrice, toPrice, bedRoomMin, bedRoomMax, bathRoomMin, bathRoomMax, hasinterior, typesale));
		if(getSearchPropForSale().size()==0){
			this.setCheckSize1(false);
		}else{this.setCheckSize1(true);}
		this.nullCheck=false;
		paginator=new MPaginator(searchPropForSale);
		return getSearchPropForSale();
	}
	public ArrayList<RoomForRent> searchRoomForRentMethod() throws Exception{
		Context ctx = new InitialContext();
		Search_RoomForRentRemote proRe=(Search_RoomForRentRemote) ctx.lookup("MySweetHome/Search_RoomForRentBean/remote");
		processField();
		setSearchRoomForRent(proRe.searchRoomForRent(title, address,fromPrice, toPrice, rentpriceFrom, rentpriceTo));
		if(getSearchRoomForRent().size()==0){
			this.setCheckSize2(false);
		}else{this.setCheckSize2(true);}
		this.nullCheck=false;
		paginator=new MPaginator(searchRoomForRent);
		return getSearchRoomForRent();
		
	}
	private void processField(){
		if(getBedroom()==0){
			bedRoomMin=0;
			bedRoomMax=100;
		}else if(getBedroom()==11){
			bedRoomMin=11;
			bedRoomMax=100;
		}else{
			bedRoomMin=getBedroom();
			bedRoomMax=getBedroom()+1;
		}
		if(getBathroom()==0){
			bathRoomMin=0;
			bathRoomMax=100;
		}else if(getBathroom()==11){
			bathRoomMin=11;
			bathRoomMax=100;
		}else{
			bathRoomMin=getBathroom();
			bathRoomMax=getBathroom()+1;
		}
		if(toPrice==6000000.0){
			toPrice=1E18;
		}else if(toPrice==0){
			toPrice=1E18;
		}
		if(rentpriceTo==1100000.0){
			rentpriceTo=1E18;
		}else if(rentpriceTo==0){
			rentpriceTo=1E18;
		}
	}
	public void setNullCheck(boolean nullCheck) {
		this.nullCheck = nullCheck;
	}
	public boolean isNullCheck() {
		return nullCheck;
	}
	public void setCurrentPropID(String currentPropID) {
		this.currentPropID = currentPropID;
	}
	public String getCurrentPropID() {
		return currentPropID;
	}



	public void setSearchPropForRent(ArrayList<PropForRent> searchPropForRent) {
		this.searchPropForRent = searchPropForRent;
	}



	public ArrayList<PropForRent> getSearchPropForRent() {
		return searchPropForRent;
	}



	


	


	



	public void setSelectedProType(String selectedProType) {
		this.selectedProType = selectedProType;
	}



	public String getSelectedProType() {
		return selectedProType;
	}





	public void setFindImages(ArrayList<Property_Image> findImages) {
		this.findImages = findImages;
	}



	public ArrayList<Property_Image> getFindImages() {
		return findImages;
	}



	


	public void setAddr(String addr) {
		this.addr = addr;
	}



	public String getAddr() {
		return addr;
	}



	public void setTitle(String title) {
		this.title = title;
	}



	public String getTitle() {
		return title;
	}



	public void setAddress(String address) {
		this.address = address;
	}



	public String getAddress() {
		return address;
	}



	public void setState(String state) {
		this.state = state;
	}



	public String getState() {
		return state;
	}



	


	public void setRentpriceFrom(double rentpriceFrom) {
		this.rentpriceFrom = rentpriceFrom;
	}



	public double getRentpriceFrom() {
		return rentpriceFrom;
	}



	public void setRentpriceTo(double rentpriceTo) {
		this.rentpriceTo = rentpriceTo;
	}



	public double getRentpriceTo() {
		return rentpriceTo;
	}



	public void setTypesale(String typesale) {
		this.typesale = typesale;
	}



	public String getTypesale() {
		return typesale;
	}



	


	public void setStatus(String status) {
		this.status = status;
	}



	public String getStatus() {
		return status;
	}



	public void setHasinterior(String hasinterior) {
		this.hasinterior = hasinterior;
	}



	public String getHasinterior() {
		return hasinterior;
	}



	



	public void setSquareMin(double squareMin) {
		this.squareMin = squareMin;
	}



	public double getSquareMin() {
		return squareMin;
	}



	public void setSquareMax(double squareMax) {
		this.squareMax = squareMax;
	}



	public double getSquareMax() {
		return squareMax;
	}










	




	public void setPrice(double price) {
		this.price = price;
	}



	public double getPrice() {
		return price;
	}



	public void setSquare(double square) {
		this.square = square;
	}



	public double getSquare() {
		return square;
	}



	public void setRent(double rent) {
		this.rent = rent;
	}



	public double getRent() {
		return rent;
	}



	public void setCheckSize(boolean checkSize) {
		this.checkSize = checkSize;
	}



	public boolean isCheckSize() {
		return checkSize;
	}






	




	public void setFromPrice(double fromPrice) {
		this.fromPrice = fromPrice;
	}



	public double getFromPrice() {
		return fromPrice;
	}



	public void setToPrice(double toPrice) {
		this.toPrice = toPrice;
	}



	public double getToPrice() {
		return toPrice;
	}



	public void setBedroom(int bedroom) {
		this.bedroom = bedroom;
	}



	public int getBedroom() {
		return bedroom;
	}



	public void setBathroom(int bathroom) {
		this.bathroom = bathroom;
	}



	public int getBathroom() {
		return bathroom;
	}



	

	public void setPaginator(MPaginator paginator) {
		this.paginator = paginator;
	}



	public MPaginator getPaginator() {
		return paginator;
	}



	public void setSearchPropForSale(ArrayList<PropForSale> searchPropForSale) {
		this.searchPropForSale = searchPropForSale;
	}



	public ArrayList<PropForSale> getSearchPropForSale() {
		return searchPropForSale;
	}



	public void setCheckSize1(boolean checkSize1) {
		this.checkSize1 = checkSize1;
	}



	public boolean isCheckSize1() {
		return checkSize1;
	}



	public void setCheckSize2(boolean checkSize2) {
		this.checkSize2 = checkSize2;
	}



	public boolean isCheckSize2() {
		return checkSize2;
	}



	public void setSearchRoomForRent(ArrayList<RoomForRent> searchRoomForRent) {
		this.searchRoomForRent = searchRoomForRent;
	}



	public ArrayList<RoomForRent> getSearchRoomForRent() {
		return searchRoomForRent;
	}



	


	


	
}
